Completed
Pull Request — develop (#85)
by Xaver
01:13
created

clientlayer.js ➔ ... ➔ L.TileLayer.extend.drawTile   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
c 0
b 0
f 0
nc 3
dl 0
loc 34
rs 8.8571
nop 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A clientlayer.js ➔ ... ➔ nodes.forEach 0 8 1
1
define(['leaflet', 'helper'],
2
  function (L, helper) {
3
    'use strict';
4
5
    return L.TileLayer.extend({
6
      setData: function (d) {
7
        this.data = d;
8
9
        // pre-calculate start angles
10
        this.data.all().forEach(function (n) {
11
          n.startAngle = (parseInt(n.node.nodeinfo.node_id.substr(10, 2), 16) / 255) * 2 * Math.PI;
12
        });
13
        this.redraw();
14
      },
15
      drawTile: function (canvas, tilePoint) {
16
        if (!this.data) {
17
          return;
18
        }
19
20
        var tileSize = this.options.tileSize;
21
        var s = tilePoint.multiplyBy(tileSize);
22
        var map = this._map;
23
24
        var margin = 50;
25
        var bbox = helper.getTileBBox(s, map, tileSize, margin);
26
27
        var nodes = this.data.search(bbox);
28
29
        if (nodes.length === 0) {
30
          return;
31
        }
32
33
        var ctx = canvas.getContext('2d');
34
        var startDistance = 12;
35
36
        ctx.beginPath();
37
        nodes.forEach(function (d) {
38
          var p = map.project([d.node.nodeinfo.location.latitude, d.node.nodeinfo.location.longitude]);
39
40
          p.x -= s.x;
41
          p.y -= s.y;
42
43
          helper.positionClients(ctx, p, d.startAngle, d.node.statistics.clients, startDistance);
44
        });
45
46
        ctx.fillStyle = 'rgba(220, 0, 103, 0.7)';
47
        ctx.fill();
48
      }
49
    });
50
  });
51